package com.lcredu.mapper;

import com.lcredu.entity.Pet;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * @author 黎长容
 * @date 2025-07-31 23:43
 */
public interface PetMapperAnnotation {
    /**
     * 黎长容知识
     *  1.  @Results中 也可以设置id值 标签为id 且如果要复用使用  @ResultMap("petMap")
     *  2. 返回一个对象用one = @One 返回一组对象用many = @Many
     */
    @Select(" select *\n" +
            "        from mybatis_pet\n" +
            "        where user_id = #{userId};")
    @Results(id = "petMap",value = {
            @Result(property = "id", column = "id", id = true),
            @Result(property = "nickname", column = "nickname"),
            @Result(property = "user", column = "user_id", one = @One(
                    select = "com.lcredu.mapper.UserMapperAnnotation.getUserById"
            ))
    })
    public List<Pet> getPetByUserId(Integer userId);

    @Select("select * from mybatis_pet where id = #{id} ")
    @ResultMap("petMap")
    public Pet getPetById(Integer id);
}
